package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 难度级别枚举
 *
 * 统一的难度级别管理，用于各种需要难度控制的场景
 * 替代分散在各个实体中的重复难度级别定义
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-13
 */
public enum DifficultyLevel implements BaseEnum {

    /**
     * 非常简单
     */
    VERY_EASY("VERY_EASY", "非常简单"),

    /**
     * 简单
     */
    EASY("EASY", "简单"),

    /**
     * 较简单
     */
    SIMPLE("SIMPLE", "较简单"),

    /**
     * 中等
     */
    MEDIUM("MEDIUM", "中等"),

    /**
     * 较难
     */
    CHALLENGING("CHALLENGING", "较难"),

    /**
     * 困难
     */
    HARD("HARD", "困难"),

    /**
     * 非常困难
     */
    VERY_HARD("VERY_HARD", "非常困难"),

    /**
     * 极难
     */
    EXTREME("EXTREME", "极难");

    private final String code;
    private final String description;

    DifficultyLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值，MEDIUM如果未找到
     */
    public static DifficultyLevel fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return MEDIUM;
        }

        for (DifficultyLevel level : values()) {
            if (level.getCode().equals(code)) {
                return level;
            }
        }
        return MEDIUM;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}